package pl.perseus.action;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

import org.springframework.beans.factory.annotation.Autowired;

import pl.perseus.model.Classes;
import pl.perseus.service.classes.IClassesService;

public class GetClassesAction extends BaseAction {

	@Autowired
	IClassesService classesService;
	
	@Getter
	@Setter
	Map<String, Object> result;
	
	@Override
	public String execute() {
		result = new HashMap<String, Object>();
		List<Classes> list = classesService.getClassesForUser(getCurrentUserLogin());
		List<Map<String, String>> items = new LinkedList<Map<String, String>>();
		
		for(Classes c : list){
			Map<String, String> map = new HashMap<String, String>();
			map.put("id", c.getId().toString());
			map.put("name", c.getClassname());
			
			items.add(map);
		}
		
		result.put("identifier", "id");
		result.put("items", items);
		
		return SUCCESS;
	}

}
